/*-----------------------------------------------------------------------------
File: ProcessInputFiles.cpp

History:
02/28/11  jnr   spun processing modules off into their own .cpp/.h files
-----------------------------------------------------------------------------*/
#include "stdafx.h"
#include "ProcessInputFiles.h"

bool processFile(char *pathToProject, WIN32_FIND_DATA fd)
{
	char buffer[MAX_PATH];
	char *extension = strrchr(fd.cFileName, '.');
	
	//TODO: this seems like an area we'd want to instill a pattern to be able 
	//to dynamcally add new file types to process
	if(!extension || (strcmp(extension,".cpp") != 0 && strcmp(extension,".h") != 0))
	   return false;

	if(DEBUG_MESSAGE_BOX)
	{
		sprintf(buffer,"Processing %s", fd.cFileName);
		MessageBox(0, buffer, "cplusplusdoc",MB_OK);
	}
    	
	return true;
}

bool FindFilesInProject(char *PathToProject)
{
	char PathToProjectPlusWildCard[MAX_PATH];
	sprintf(PathToProjectPlusWildCard,"%s", PathToProject);	
	strcat(PathToProjectPlusWildCard, "\\*.*");
	HANDLE hSearch = NULL;
	WIN32_FIND_DATA fd;
	
	bool more_files = true;
	hSearch = FindFirstFile (PathToProjectPlusWildCard,&fd);

	if(INVALID_HANDLE_VALUE == hSearch) 
	{
		MessageBox(0,"No files found under this directory.", "Error",MB_OK);
		hSearch = NULL;
		return false;
	}
	else
	{
		do
		{
			if(processFile(PathToProject, fd))
				read_comments(PathToProject, fd);
			
			if(!FindNextFile(hSearch,&fd))
			{
				if(ERROR_NO_MORE_FILES == GetLastError())
				{
					more_files = FALSE;
				}
			}	
		}while(more_files);

		if(DEBUG_MESSAGE_BOX)
			MessageBox(0, "All Done!", "cplusplusdoc",MB_OK);
	}
	return true;
}